<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>短信营销1-创建3</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="stylesheet" type="text/css"
	href="<%=path%>/css/marketing/public.css" />
    <link rel="stylesheet" type="text/css"
	href="<%=path%>/css/marketing/style_list.css" />
	<link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/mobile_coupon_public.css" />
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/mobile_coupon_style.css" />
	
    <link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
	<link href="<%=path%>/hplus/css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css">
    <link href="<%=path%>/css/marketing/s_style.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/switchery/switchery.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
        <style> 
        .radio label{
            padding-left: 0;
        }

        .date{
            margin: -8px 20px 0 0;
        }

        .clockpicker{
            margin-top: -8px;
        }

        .i-checks label{
            float: left;
            margin-right: 10px;
        }

        .col-sm-offset-1{
            margin-top: 20px;
        }

        .tishi{
            margin-top: 7px;
            
        }

        .alert{
            position:absolute;
            top: -15px;
            left: 8%;
            display:none;
        }
        .text-center{
            width:50%;
            margin: 10px 0 20px;
        }
        
        .bbb{
        	width:13%;
        	float:left;
        }
        
       /*  .col-md-8{
        	border-right:1px solid #ddd;
        } */
        
        .s_phone_bg{
        	background:url('<%=path%>/images/marketing/img_mobile.png') no-repeat;
        	background-size:100% 100%;
        	width:342px;
        	height:447px;
        }
        
        .s_textarea{
        	background:#e5e5ea;
        	position: absolute;
		    top: 200px;
		    left: 109px;
		    width:165px;
		    border-radius:10px;
		    padding:6px;
        }
        .red{
            color: red;
            margin-right: 5px;
        }
    </style>
</head>

<body class="gray-bg" id="parentBody">
    <div class="wrapper wrapper-content">
	    <div class="row">
	      <div class="ibox-content col-md-12">
            <form method="get" class="form-horizontal col-sm-8">
                <div class="form-group">
                   <label class="col-sm-2 control-label"><span class="red" style="margin-right:2px">*</span>项目名称</label>
                   
                   <div class="col-sm-5">
                       <input id="couponBatchName" type="text"  class="form-control" maxlength="20" onblur="checkLength(this)">
                   </div>
                </div>
            </form>
          </div>
	      <div class="ibox-content col-md-12" style="margin-top:10px">
	         <form method="get" class="form-horizontal col-sm-8">
                <div class="form-group">
                   <label class="col-sm-2 control-label">1.优惠券</label>
                </div>
            </form>
          </div>
	      <div class="col-md-12 ibox-content">
	        <div class="col-md-8">
		        <form method="get" class="form-horizontal">
		            <div class="form-group">
	                   <label class="col-sm-2 control-label">选择优惠券</label>
	                    <div class="col-sm-10" style="margin-left:-14px">
	                       <div class="col-sm-10">
		                        <div class="radio i-checks col-sm-3">
		                            <label class="operation">
		                                <input type="radio" checked=""  id="newCouponRadio" name="choseCoupon" value="5"> <i></i>新建优惠券</label>
		                        </div>
		                        <div class="radio i-checks  col-sm-4">
		                            <label class="operation">
		                                <input type="radio"  id="newCouponRadioNo" name="choseCoupon" value="10"> <i></i>选择已有优惠券</label>
		                        </div>
	                       </div>
	                       
	                    </div>
	                </div>        
		            <div class="form-group" id="choseCouponYet" hidden="">
	                    <label class="col-sm-2 control-label">优惠券选择</label>
	                       <div class="col-sm-4">
	                          <input id="choseCouponInput" type="text"  readonly="readonly" class="form-control" data-toggle="modal" href="<%=path%>/view/coupon/modalCouponMultiple" data-target="#coupon_modal">
	                       </div>
	                </div>
		        
	                <div class="form-group newCoupon">
	                   <label class="col-sm-2 control-label">惠券名称</label>
	                    <div class="col-sm-7">
	                        <div class="radio i-checks col-sm-3">
	                            <label class="operation">
	                                <input type="radio" checked="" id="yes" name="coupon_type" value="0"> <i></i>优惠券</label>
	                        </div>
	                        <div class="radio i-checks col-sm-3">
	                            <label class="operation">
	                                <input type="radio" id="no" name="coupon_type" value="1"> <i></i> 物品券</label>
	                        </div>
	                        <div class="col-sm-4">
                                    <input type="text" id="name" placeholder="请输入名称" class="form-control" maxlength="20" onblur="checkLength(this)" oninput="reloadRight()">
                            </div>
	                    </div>
	                    
	                </div>
	
	                <div class="form-group newCoupon priceGroup">
	                   <label class="col-sm-2 control-label">金额</label>
	                    <div class="col-sm-10">
	                       <div class="col-sm-12" style="margin-left:-14px">
		                        <div class="bbb radio i-checks">
		                            <label class="operation priceLab">
		                                <input type="radio" checked=""  name="faceValue" value="5" > <i></i>5元</label>
		                        </div>
		                        <div class="bbb radio i-checks">
		                            <label class="operation priceLab">
		                                <input type="radio" id="no" name="faceValue" value="10" > <i></i>10元</label>
		                        </div>
		                         <div class="bbb radio i-checks">
		                            <label class="operation priceLab">
		                                <input type="radio"   name="faceValue" value="20"> <i></i>20元</label>
		                        </div>
		                        <div class="bbb radio i-checks">
		                            <label class="operation priceLab">
		                                <input type="radio" id="no" name="faceValue" value="50"> <i></i>50元</label>
		                        </div>
		                         <div class="bbb radio i-checks">
		                            <label class="operation priceLab">
		                                <input type="radio"   name="faceValue" value="100"> <i></i>100元</label>
		                        </div>
	                       </div>
	                       <div class="col-sm-12" style="margin-left:-14px;margin-top:10px">
	                            <div class="radio i-checks" style="width:40%;float:left;">
		                            <label class="operation">
		                                <input type="radio"   name="faceValue" value="-1" id="defined_value_radio"> <i></i>自定义</label>
		                                <div class="col-sm-6">
				                             <input type="text" class="form-control" id="defined_value" disabled="disabled" style="margin-top:-8px;margin-left:-10px;"   onkeyup="num(this)" maxlength="5">
			                            </div>
		                        </div>
	                       </div> 
	                        
	                    </div>
	                </div>
	
	               <div class="form-group newCoupon">
	                    <label class="col-sm-2 control-label">有效日期</label>
	                    <div class="col-sm-7">
	                        <div class="form-group col-sm-4">
		                        <select id="validity_period_type" class="form-control" name="account" >
			                        <option value="0">固定有效期</option>
			                        <option value="1">相对有效期</option>
			                    </select>
		                    </div>
		                     <div class="form-group col-sm-8" id="choseExpireTime">
			                    <div class="input-daterange input-group" id="datepicker" style="padding-left:15px">
			                        <input id="start_time" type="text" class="input-sm form-control" name="start" value="2018-1-3" onchange="startTimeChange()"/>
			                        <span class="input-group-addon">至</span>
			                        <input id="end_time" type="text" class="input-sm form-control" name="end" value="2018-2-3" onchange="endTimeChange()"/>
			                    </div>
			                </div>  
			                 <div hidden="" class="col-sm-5" id="choseAfterDay">
			                    <div class="col-sm-10" >
	                               <input type="text" id="afterDay" class="form-control" onkeypress="keyPress()" maxlength="2">
	                            </div>
	                            <span class="col-sm-2 text-left" style="margin-left:-10px;margin-top:8px">天</span>
			                </div>  
	                    </div>
	                </div>
	
	               <div class="form-group newCoupon" id="useCondition">
	                    <label class="col-sm-2 control-label">使用条件</label>
	                    <div class="col-sm-8">
	                        <div class="col-sm-3" style="margin-left:-14px">
                               <label class="checkbox-inline i-checks" ><input id="limit_price_check" type="checkbox" value="option1">订单满</label>
                            </div>
	                        <div class="col-sm-3" style="margin-left:-50px">
                               <input type="text" id="limit_price" disabled="disabled" class="form-control"  onkeyup="num(this)" maxlength="5">
                            </div>
                            <span class="col-sm-2 text-left" style="margin-left:-10px;margin-top:8px">元使用</span>
	                    </div>
	               </div>
	               
	               <div class="form-group newCoupon">
	                    <label class="col-sm-2 control-label">使用时段</label>
	                    <div class="col-sm-10">
	                    
	                           <div class="col-sm-12" style="margin-left:-14px">
		                           <label class="checkbox-inline i-checks choseWeekLable"><input id="no_set" checked="checked" type="checkbox" value="">不设</label>
	                              	                              
	                           </div>
	                           <div class="col-sm-12 no_set" style="margin-left:-14px" hidden="">
	                               <label class="checkbox-inline i-checks choseWeekLable"><input id="chose_week1" class="choseWeek" type="checkbox" value="周一">周一</label>
	                               <label class="checkbox-inline i-checks choseWeekLable"><input id="chose_week2" class="choseWeek" type="checkbox" value="周二">周二</label>
	                               <label class="checkbox-inline i-checks choseWeekLable"><input id="chose_week3" class="choseWeek" type="checkbox" value="周三">周三</label>
	                               <label class="checkbox-inline i-checks choseWeekLable"><input id="chose_week4" class="choseWeek" type="checkbox" value="周四">周四</label>
	                               <label class="checkbox-inline i-checks choseWeekLable"><input id="chose_week5" class="choseWeek" type="checkbox" value="周五">周五</label>
	                               <label class="checkbox-inline i-checks choseWeekLable"><input id="chose_week6" class="choseWeek" type="checkbox" value="周六">周六</label>
	                               <label class="checkbox-inline i-checks choseWeekLable"><input id="chose_week7" class="choseWeek" type="checkbox" value="周日">周日</label>
	                           </div>
	                           <div class="col-sm-7 no_set" style="margin-left:-23px;margin-top:8px" hidden="">
	                               <div class="col-sm-4" style="margin-left:-20px;float:left;">
	                                 <label class="checkbox-inline i-checks" style="float:right"><input id="periodTimeHourFlag" disabled="disabled" type="checkbox" value="option1">时间</label>
	                               </div>
		                           <div class="input-group clockpicker col-sm-3" style="float:left;margin-top:1px" data-autoclose="true">
		                                <input id="start_hour" disabled="disabled"  type="text" class="form-control periodTimeHour" value="09:00" onchange="startTimeHourChange()">
		                           </div>
		                           <div class="col-sm-1" style="margin-top:8px">
		                                <span class="text-center" >至</span>
		                           </div>
		                            
		                            <div class="input-group clockpicker col-sm-3" style="float:left;margin-top:1px" data-autoclose="true">
		                                <input id="end_hour"  disabled="disabled" type="text" class="form-control periodTimeHour" value="22:00" onchange="endTimeHourChange()">
		                           </div>
	                           </div>
	                    </div>
	               </div>
	               
	               <div class="form-group newCoupon">
	                   <label class="col-sm-2 control-label">使用规则</label>
	                    <div class="col-sm-10" style="margin-left:-14px">
	                       <div class="col-sm-12">
		                        <div class="radio i-checks col-sm-3">
		                            <label class="operation">
		                                <input type="radio" checked=""  name="useRule" value="0"> <i></i>单张使用</label>
		                        </div>
		                        <div class="radio i-checks  col-sm-3">
		                            <label class="operation">
		                                <input type="radio" id="no" name="useRule" value="1"> <i></i>多张使用</label>
		                        </div>
	                       </div>
	                       
	                    </div>
	                </div>
	                <div class="form-group newCoupon">
	                   <label class="col-sm-2 control-label" >使用说明</label>
	                    <div class="col-sm-6">                      
	                        <textarea  id="useDesc"  class="form-control" required="" aria-required="true" style="height:150px;"></textarea>                       
	                    </div>
	                </div>
	               <%--  <div class="form-group newCoupon">
	                    <label class="col-sm-2 control-label">参与门店</label>
	                       <div class="col-sm-2">
	                          <input id="choseStoreIds" type="text" value="选择门店" readonly="readonly" class="form-control" data-toggle="modal" href="<%=path%>/api/bm/ui/store" data-target="#store_modal">
	                       </div>
	                </div> --%>
	                 <div class="form-group">
	                   <label class="col-sm-2 control-label">短信通知</label>
	                    <div class="col-sm-7" style="margin-left:-14px">
	                       <div class="col-sm-12">
		                        <div class="radio i-checks col-sm-3">
		                            <label class="operation">
		                                <input type="radio" checked=""  name="smsInform" id="smsInform" value="5"> <i></i>是</label>
		                        </div>
		                      <div class="radio i-checks  col-sm-3">
		                            <label class="operation">
		                                <input type="radio"  name="smsInform" id="smsInformNo" value="10"> <i></i>否</label>
		                      </div>
	                       </div>
	                       
	                    </div>
	                </div>         
	            </form>
	        </div>
	        <div class="col-md-4" hidden="">
	            <h3 style="text-align:center;">优惠券预览</h3>
	            <div class="container" style="width:355px;margin:0 auto;">
                    <ul class="surrent" style="width:355px;height:143px;">
			            <li id="right_coupon" class="coupon_yellow">
		                    <div class="left">
		                    	<b>￥</b>
		                        <span id="right_price">5</span>
		                    </div>
		                    <div class="right">
		                        <i title="" class="coupon_name_right">优惠券</i>
		                        <i class="limit_condition"  hidden="">满200元使用</i>
		                        <em class="right_hour">2017-12-27-2018-1-27</em>
		                    </div>
		                    <p class="right_time" hidden="">使用时间:周一、周三、周五 12:00-14:00</p>
		                </li>
		                
		                 <li id="right_voucher" class="coupon_yellow s_coupon" hidden="">
		                    <h2 title="" class="coupon_name_right">物品券</h2>
		                    <h3 class="limit_condition"  hidden="">满200元使用</h3>
		                    <em class="right_hour">2017-12-27-2018-1-27</em>
		                    <p class="right_time" hidden="">使用时间:周一、周三、周五 12:00-14:00</p>
		                </li>
		             </ul>
		          </div>      
	        </div>
	      </div>  
	      <!-- <div class="ibox-content col-md-12 smsSetting" style="margin-top:10px">
	               <div class="col-sm-5"></div>
                   <h4 class="col-sm-2">短信设置</h4>
                   <div class="col-sm-5"></div>
          </div> -->
          <div class="ibox-content col-md-12 smsSetting" style="margin-top:10px">
	         <form method="get" class="form-horizontal col-sm-8">
                <div class="form-group">
                   <label class="col-sm-2 control-label">2.短信配置</label>
                </div>
            </form>
          </div>
	      <div class="col-md-12 ibox-content smsSetting">
		      <div class="col-md-8" style="border-right:1px solid #ddd;">
	            <form method="get" class="form-horizontal">
	
	                 <div class="form-group">
	                    <label class="col-sm-2 control-label" data-toggle="modal" data-target="#myModal5">短信签名</label>
	                    <div class="col-sm-5">
	                        <select id="autograph" class="form-control" name="account" onchange="reloadCountWordNum()"><option></option></select>
	                    </div>
	                                   
	                </div>
	
	               <div class="form-group">
	                    <label class="col-sm-2 control-label">插入链接</label>
	                    <div class="col-sm-10" style="margin-left:-14px">
	                       <div class="col-sm-12">
		                        <div class="radio i-checks col-sm-3">
		                            <label class="operation">
		                                <input type="radio" checked=""  id="insertShortUrl" name="insertUrl" value="[活动短链]"> <i></i>活动短链</label>
		                        </div>
		                       <div class="col-sm-5" style="margin-left:-60px">
	                            <div class="input-group" style="width: 100%;">
	                                <input type="text" class="form-control" id="testNoBtn" style="position: relative; border-radius: 4px;" autocomplete="off">
	                                <i class="fa fa-times-circle clear" style="position:absolute;display:inline-block;right:25px;top:10px;z-index:232"></i>
	                                <div class="input-group-btn">
	                                    <button type="button" class="btn btn-white dropdown-toggle" data-toggle="" style="display: none;">
	                                        <span class="caret"></span>
	                                    </button>
	                                    <ul class="dropdown-menu dropdown-menu-right" role="menu" style="padding-top: 0px; max-height: 375px; max-width: 800px; overflow: auto; width: auto; transition: 0.3s;"></ul>
	                                </div>
	                                <!-- /btn-group -->
	                            </div>
	                         </div>
	                       </div>
	                       
	                    </div>
	                </div>
	                <div class="form-group">
	                   <label class="col-sm-2 control-label"></label>
	                    <div class="col-sm-10" style="margin-left:-14px;margin-top:-10px">
	                       <div class="col-sm-12">
		                        <div class="radio i-checks col-sm-2">
		                            <label class="operation">
		                                <input type="radio"  id="insertCouponUrl" name="insertUrl" value="[券列表]"> <i></i>券列表</label>
		                        </div>
	                       </div>
	                       
	                    </div>
	                </div>
	                
	                <div class="form-group">
		                  <label class="col-sm-2 control-label">短信内容</label>
		                  <div class="input-group m-b col-sm-5" style="padding-left:15px;float:left;">
			                  <span class="input-group-addon">变量</span>
			                  <select id="variableSmsSelect" class="form-control" name="account" onchange="reloadCountWordNum()">
						         <option selected="" value="[会员名称]">会员名称</option>
			                  </select>
			                  <span class="input-group-addon"><i id="addSmsVariable" class="fa fa-plus"></i></span> 
		                  </div>
                    </div>
                    <div class="form-group">
	                   <label class="col-sm-2 control-label" style="visibility: hidden"></label>
	                    <div class="col-sm-5" style="margin-top:-10px;">                      
	                        <textarea oninput="reloadCountWordNum()" id="smsContent" name="comment" class="form-control" required="" aria-required="true" style="height:150px;"></textarea>                       
		                    <div  class=" text-right"> 
		                       <h6 class="col-sm-9 "></h6> <span class="text-right" id="current">70</span><span>/</span><span id="remain" class="text-left">0</span><span>条</span>
		                    </div>
	                    </div>
	                    
	                </div>
	                
	                <div class="form-group">
	                   <label class="col-sm-2 control-label">到期提醒</label>
	                    <div class="col-sm-10" style="margin-left:-14px">
	                       <div class="col-sm-12">
	                            <div class="radio i-checks col-sm-2">
		                            <label class="operation">
		                            <input type="radio" id="expireRemindRadioNo" name="expireRemind" value="10"> <i></i>否</label>
		                        </div>
		                        <div class="radio i-checks col-sm-9">
		                            <label class="operation">
		                            <input type="radio" checked=""  name="expireRemind" id="expireRemindRadio" value="5"> <i></i>是</label>
	                                <div id="expirePrompt" class="col-sm-10" style="margin-left:-30px;margin-top:1px">
	                                     <div class="col-sm-3">
	                                          <span class="text-left" style="margin-top:8px">到期前</span>
	                                     </div>
	                                     <div class="col-sm-5" style="margin-left:-30px">
	                                          <input type="text" class="form-control" id="expireDay" style="margin-top:-8px;" onkeyup="num(this)" maxlength="1">
	                                     </div>
			                             <div class="col-sm-5" style="margin-left:-25px">
	                                          <span class="text-left" style="margin-top:8px">天提醒</span>
	                                     </div>
		                            </div>
		                        </div>
	                       </div>
	                    </div>
	                </div>        
	                
                    <div class="form-group expireRemind">
		                  <label class="col-sm-2 control-label">提醒内容</label>
		                  <div class="input-group m-b col-sm-5" style="padding-left:15px;float:left;">
			                  <span class="input-group-addon">变量</span>
			                  <select id="variableExpireSelect" class="form-control" name="account">
						          <option selected="" value="[会员名称]">会员名称</option>
			                  </select> 
			                  <span class="input-group-addon"><i id="addExpireVariable" class="fa fa-plus"></i></span>
		                  </div>
                    </div>
                    <div class="form-group expireRemind">
	                   <label class="col-sm-2 control-label" style="visibility: hidden"></label>
	                    <div class="col-sm-5" style="margin-top:-10px;">                      
	                        <textarea oninput="reloadCountWordNumExpire()" id="ccomment" name="comment" class="form-control" required="" aria-required="true" style="height:150px;"></textarea>                       
		                    <div  class=" text-right"> 
		                       <h6 class="col-sm-9 "></h6> <span class="text-right" id="current_expire">70</span><span>/</span><span id="remain_expire" class="text-left">0</span><span>条</span>
		                    </div>
	                    </div>
	                </div>
	             
	            </form>
	          </div>
	          <div class="col-md-4">
	            <h3 style="text-align:center;">页面展示区域</h3>
	            <div class="s_phone_bg">
	            	<p class="s_textarea"></p>
	            </div>
	        </div>
         </div>
	      <div class="ibox-content col-md-12">
	          <div class="col-md-8">
	             <label class="col-sm-1 control-label" style="visibility: hidden"></label>
	             <div class="col-sm-5 col-sm-offset-1">
                     <button onclick="javascript:cancel();" type="button" class="btn btn-outline btn-primary" style="margin-right:20px;">取消</button>
                     <button onclick="javascript:save();" type="button" class="btn  btn-primary"  style="margin-right:20px;">保存</button>
                     <button id="btnSubmitAudit" onclick="javascript:;" type="button" class="btn  btn-primary smsSetting">提交审核</button>
                 </div>
              </div>   
          </div> 
	    </div>    
    </div>
    
    <div class="modal inmodal fade" id="store_modal" tabindex="-1" role="dialog"  aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
            </div>
        </div>
    </div>
    <div class="modal inmodal fade" id="coupon_modal" tabindex="-1" role="dialog"  aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
               
            </div>
        </div>
    </div>
    <script src="<%=path%>/hplus/js/jquery.min.js?v=2.1.4"></script>
    <script src="<%=path%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="<%=path%>/hplus/js/plugins/chosen/chosen.jquery.js"></script>
    <script src="<%=path%>/hplus/js/plugins/jsKnob/jquery.knob.js"></script>
    <script src="<%=path%>/hplus/js/plugins/jasny/jasny-bootstrap.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="<%=path%>/hplus/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
    <script src="<%=path%>/hplus/js/plugins/switchery/switchery.js"></script>
    <script src="<%=path%>/hplus/js/plugins/ionRangeSlider/ion.rangeSlider.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="<%=path%>/hplus/js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/clockpicker/clockpicker.js"></script>
    <script src="<%=path%>/hplus/js/plugins/cropper/cropper.min.js"></script>
    
    <script src="<%=path%>/hplus/js/demo/form-advanced-demo.min.js"></script>
	<script src="<%=path%>/hplus/js/plugins/suggest/bootstrap-suggest.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
    <script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/lengthlimit.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
	
	

    <script type="text/javascript">
        var showText = "[活动短链]";
        $(document).on('ifChecked', '#limit_price_check', function() {
		   	limitPriceFlag=true;
		   	$("#limit_price").removeAttr("disabled");
		   	$('.limit_condition').show();
	    });
	    $(document).on('ifUnchecked', '#limit_price_check', function() {
		   	limitPriceFlag=false;
		   	$("#limit_price").attr("disabled","disabled");
		   	$('.limit_condition').hide();
	    });
	    $(document).on('ifChecked', '#no_set', function() {
	    	$(".choseWeek").attr("disabled","disabled");
	    	$(".choseWeek").parent().removeClass("checked");
	    	$("#periodTimeHourFlag").attr("disabled","disabled");
	    	$("#periodTimeHourFlag").parent().removeClass("checked");
	    	$(".periodTimeHour").attr("disabled","disabled");
	    	useTimeType=0;
	    	$('.no_set').hide();
	    	$(".right_time").hide();
	    });
	    $(document).on('ifUnchecked', '#no_set', function() {
	    	$(".choseWeek").removeAttr("disabled");
	    	$("#periodTimeHourFlag").removeAttr("disabled");
	    	$("#periodTimeHourFlag").parent().removeClass("disabled");
	    	$('.no_set').show();
	    	$(".right_time").show();
	    	useTimeType=1;
	    });
	    $(document).on('ifChecked', '#periodTimeHourFlag', function() {
	    	periodTimeHourFlag=true;
	    	$(".periodTimeHour").removeAttr("disabled");
	    	var startHour=$('#start_hour').val();
			var endHour=$('#end_hour').val();
			periodTimeHour=startHour+"-"+endHour;
	    	reload();
	    });
	    $(document).on('ifUnchecked', '#periodTimeHourFlag', function() {
	    	periodTimeHourFlag=false;
	    	$(".periodTimeHour").attr("disabled","disabled");
	    	periodTimeHour="";
	    	reload();
	    });
	    $("#validity_period_type").change(function(){  
	    	validityPeriodType=$(this).children('option:selected').val();
	    	if(validityPeriodType==0){
	    		$("#choseAfterDay").hide();
	    		$("#choseExpireTime").show();
	    	}else if(validityPeriodType==1){
	    		$("#choseExpireTime").hide();
	    		$("#choseAfterDay").show();
	    	}
	    	reloadRight();
	    }) 
	    $(document).on('ifChecked', '#defined_value_radio', function() {
	    	$("#defined_value").removeAttr("disabled");
	    	definedValueFlag=true;
	    	reloadRight();
	    });
	    $(document).on('ifUnchecked', '#defined_value_radio', function() {
	    	$("#defined_value").attr("disabled","disabled");
	    	definedValueFlag=false;
	    });

	    $(document).on('ifChecked', '#newCouponRadio', function() {
	    	newCouponModel=true;
	    	$('#choseCouponYet').hide();
	    	$('.newCoupon').show();
	    	$("#right_coupon").css("background-image", "url('<%=path%>/images/marketing/yellow.png')");
	    	reloadRight();
	    });
	    
	    $(document).on('ifUnchecked', '#newCouponRadio', function() {
	    	newCouponModel=false;
	    	$('.newCoupon').hide();
	    	$('#choseCouponYet').show();
	    	$('.right_time').show();
	    	$('.limit_condition').show();
	    	$('.right_hour').show();
	    	$("#right_coupon").css("background-image", "url('<%=path%>/images/marketing/yellow_demo.png')");
	    });
	    $(document).on('ifChecked', '#yes', function() {
	    	
	    	$('.priceGroup').show();
	    	$('#right_coupon').show();
	    	$('#right_voucher').hide();
	    	//$('#useCondition').show();
	    	
	    });
	    
	    $(document).on('ifUnchecked', '#yes', function() {
	    	
	    	$('.priceGroup').hide();
	    	$('#right_coupon').hide();
	    	$('#right_voucher').show();
	    	//$('#useCondition').hide();
	    	
	    });
	    $(document).on('ifChecked', '#smsInform', function() {
	    	smsInformFlag=1;
	    	$('.smsSetting').show();
	    	
	    });
	    $(document).on('ifUnchecked', '#smsInform', function() {
	    	smsInformFlag=0;
	    	expireRemindFlag=0;
	    	$('.smsSetting').hide();
	    	
	    });
	    $(document).on('ifChecked', '#expireRemindRadio', function() {
	    	expireRemindFlag=1;
	    	$('.expireRemind').show();
	    	$('#expirePrompt').show();
	    	
	    });
	    $(document).on('ifUnchecked', '#expireRemindRadio', function() {
	    	expireRemindFlag=0;
	    	$('.expireRemind').hide();
	    	$('#expirePrompt').hide();
	    	
	    });
	    
	    $(document).on('ifChecked', '#insertShortUrl', function() {
	    	choseInsertActivityUrl=true;
	    	$('#testNoBtn').removeAttr("disabled","disabled");
	    	clearCouponUrlText();
	    });
	    $(document).on('ifUnchecked', '#insertShortUrl', function() {
	    	choseInsertActivityUrl=false;
	    	
	    	$('#testNoBtn').attr("disabled","disabled");
	    	$("#smsContent").val($("#smsContent").val()+"[券列表]");
	    	clearShowText();
	    	
	    });
	    
	    $('.choseWeekLable').on('ifChecked', function(event){
        	$(this).children().addClass("checked");
        	reload();
        });
        $('.choseWeekLable').on('ifUnchecked', function(event){
        	$(this).children().removeClass("checked");
        	reload();
        });
        
        
        
        
        /* $dlg.on('hidden.bs.modal', function (e) {
            if ($(".modal.fade.in").length > 0) $("body:not(.modal-open)").addClass("modal-open");
        }); */
        
        var couponModalStatus=false;
    	//监听优惠券模态款关闭状态
        $('#coupon_modal').on('hidden.bs.modal', function () {
        	console.log("couponModalStatus----->"+couponModalStatus);
        	couponModalStatus=false;
        })
        //监听优惠券模态款打开状态
        $('#coupon_modal').on('show.bs.modal', function () {
        	console.log("couponModalStatus----->"+couponModalStatus);
        	couponModalStatus=true;
        })
        
        
       
        function colsecouponNotEnough(){
        	 $('#couponNotEnough').modal("hide");
        }
    	
        
	    function reload(){
	    	periodTimeWeek="";
	    	periodTimeHour="";
	    	$(".choseWeekLable .checked").children()
			   .each(
					function(i, d) {
						if(StringEmpty(this.id)){
							periodTimeWeek = periodTimeWeek + "," +this.value; 
						}
			});
	    	periodTimeWeek=periodTimeWeek.replace(",","");
	    	periodTimeWeek=handlePeriodTimeWeek(periodTimeWeek);
	    	if(periodTimeHourFlag){
  			    var startHour=$('#start_hour').val();
  			    var endHour=$('#end_hour').val();
  			    periodTimeHour=startHour+"-"+endHour;
	    		$('.right_time').html("使用时间:"+periodTimeWeek+" "+periodTimeHour);
	    	}else{
	    		$('.right_time').html("使用时间:"+periodTimeWeek);
	    	}
	    }
	    
	    $('.clear').on('click', function(event){
	    	clearShowText();
	    });
	    //提交审核
	    $('#btnSubmitAudit').on('click', function(event){
	    	submitAuditFlag=true;
	    	save();
	    });
	    
	    $('#addSmsVariable').on('click', function(event){
	    	var smsVariable=$("#variableSmsSelect  option:selected").val();
	    	$('#smsContent').val($('#smsContent').val()+smsVariable);
	    	reloadCountWordNum();
	    });
	    $('#addExpireVariable').on('click', function(event){
	    	var smsVariable=$("#variableExpireSelect  option:selected").val();
	    	$('#ccomment').val($('#ccomment').val()+smsVariable);
	    	reloadCountWordNumExpire();
	    });
	    
	    function clearShowText(){
	    	$('#testNoBtn').val("");
			activity_id="";
			var smsContent=$("#smsContent").val();
			smsContent=smsContent.replace(showText,"");
			$('#smsContent').val(smsContent);
			reloadCountWordNum();
	    }
	    function clearCouponUrlText(){
			var smsContent=$("#smsContent").val();
			smsContent=smsContent.replace("[券列表]","");
			$('#smsContent').val(smsContent);
			reloadCountWordNum();
	    }
	    
	    var wordLength=0;
        var smsPriceNum=1;
        //当前
        var current;
        //剩余
        var remain;
        
        var initLength=6;
        
        var shortUrl;
        var sms_content;
        //更新新短信输入数量 
        function reloadCountWordNum(){
        	initLength=6;
        	autograph_name=$("#autograph  option:selected").text();
        	if(StringEmpty(autograph_name))
        	    initLength=initLength+autograph_name.length+2;
        	sms_content=$('#smsContent').val();
        	
        	if(StringEmpty(sms_content)){
        		$('.s_textarea').text("【"+autograph_name+"】"+sms_content+" TD退订");
        	}else{
        		$('.s_textarea').text("");
        	}
        	
        	if(isHaveStr(sms_content,"[活动短链]")||isHaveStr(sms_content,"[券列表]")){
        		initLength=initLength+13;
        	}
        	if(isHaveStr(sms_content,"[会员名称]")){
        		initLength=initLength-2;
        	}
        	
        	wordLength=sms_content.length;
        	if(smsPriceNum==1){
        		smsPriceNum=parseInt(((wordLength/(70-initLength))+1));
        	}else{
        		smsPriceNum=parseInt((((wordLength+initLength)/70)+1));
        	}
        	$('#remain').html(smsPriceNum);
        	if(smsPriceNum==1){
        		current=(70-initLength)-(wordLength%70);
        	}else{
        		current=70-((wordLength+initLength)%70);
        	}
        	$('#current').html(current);
        }
        
	    var sms_remind_equivalen_num=1;
        function reloadCountWordNumExpire(){
        	var initLength=0;
        	var current=0;
        	var smsPriceNum=0;
        	autograph_name=$("#autograph  option:selected").text();
        	if(StringEmpty(autograph_name))
        	    initLength=initLength+autograph_name.length+2;
        	var content=$('#ccomment').val();
        	if(StringEmpty(content)){
        		$('.s_textarea').text("【"+autograph_name+"】"+content);
        	}else{
        		$('.s_textarea').text("");
        	}
        	var wordLength=content.length;
        	if(isHaveStr(sms_content,"[会员名称]")){
        		wordLength=wordLength-2;
        	}
        	if(smsPriceNum==1){
        		smsPriceNum=parseInt(((wordLength/(70-initLength))+1));
        	}else{
        		smsPriceNum=parseInt((((wordLength+initLength)/70)+1));
        	}
        	$('#remain_expire').html(smsPriceNum);
        	if(smsPriceNum==1){
        		current=(70-initLength)-(wordLength%70);
        	}else{
        		current=70-((wordLength+initLength)%70);
        	}
        	$('#current_expire').html(current);
        	
        }
        
        $('.priceLab').on('ifChecked', function(event){
        	reloadRight();
        });
        $('.priceLab').on('ifUnchecked', function(event){
        	reloadRight();
        });
        
        function reloadRight(){
        	
        	if(limitPriceFlag){
        		$('.limit_condition').show();
        	}else{
        		$('.limit_condition').hide();
        	}
        	if(useTimeType="0"){
        		$(".right_time").hide();
    	    	
        	}else{
        		$(".right_time").show();
        	}
        	
        	if(StringEmpty($('#name').val())){
        		$('.coupon_name_right').html($('#name').val());
        		$('.coupon_name_right').attr("title",$('#name').val());
        	}
        	
        	if(StringEmpty($('#limit_price').val())){
        		$('.limit_condition').html("满"+$('#limit_price').val()+"元使用");
        	}else{
        		$('.limit_condition').html("满0元使用");
        	}
        	
        	if(StringEmpty($("input[name='faceValue']:checked").val())){
        		var value=$("input[name='faceValue']:checked").val();
        		if(value==-1){
        			$('#right_price').html(0);
        		}else{
        			$('#right_price').html(value);
        		}
        	}
        	
        	if(definedValueFlag){
        		if(StringEmpty($('#defined_value').val())){
            		$('#right_price').html($('#defined_value').val());
            	}else{
            		$('#right_price').html('0');
            	}
        	}
        	
        	if(validityPeriodType==0){
        		 var startTime=$('#start_time').val();
  			     var endTime=$('#end_time').val();
         		 if(CompareDate(startTime,endTime)){
        			 $('#end_time').val(startTime);
        			 $('.right_hour').html(startTime+'-'+startTime);
     			  }else{
     				 $('.right_hour').html(startTime+'-'+endTime);
     			  }
        		
        		
        	}else{
        		$('.right_hour').html('有效期已发出为准');
        	}
        	
        	
        }
        
        function startTimeChange(){
        	 var startTime=$('#start_time').val();
			 var endTime=$('#end_time').val();
			   
    		 if(CompareDate(startTime,endTime)){
    			 $('#end_time').val(startTime);
    			 $('.right_hour').html(startTime+'-'+startTime);
 			  }else{
 				 $('.right_hour').html(startTime+'-'+endTime);
 			  }
        }
        function endTimeChange(){
       	     var startTime=$('#start_time').val();
			 var endTime=$('#end_time').val();
			   
	   		 if(CompareDate(startTime,endTime)){
	   			 $('#start_time').val(endTime);
	   			 $('.right_hour').html(startTime+'-'+startTime);
			 }else{
				 $('.right_hour').html(startTime+'-'+endTime);
			 }
       }
       
        function startTimeHourChange(){
     	   if(periodTimeHourFlag){
 			    var startHour=$('#start_hour').val();
 			    var endHour=$('#end_hour').val();
 			    
 			    var startHourTemp=startHour.split(":")[0];
  			    var endHourTemp=endHour.split(":")[0];
  			    
  			    if(parseInt(startHourTemp)>parseInt(endHourTemp)){
 			    	endHour=startHour;
 	 			}
  			   $('#start_hour').val(startHour);
   			  $('#end_hour').val(endHour);
 			    periodTimeHour=startHour+"-"+endHour;
 	    		$('.right_time').html("使用时间:"+periodTimeWeek+" "+periodTimeHour);
 	    	}else{
 	    		$('.right_time').html("使用时间:"+periodTimeWeek);
 	    	}
        }
        
        function endTimeHourChange(){
  			    var startHour=$('#start_hour').val();
  			    var endHour=$('#end_hour').val();
  			    var startHourTemp=startHour.split(":")[0];
  			    var endHourTemp=endHour.split(":")[0];
  			   
  			    if(parseInt(startHourTemp)>parseInt(endHourTemp)){
  				  startHour=endHour;
  			    }
  			   
  			   $('#start_hour').val(startHour);
  			  $('#end_hour').val(endHour);
  			    periodTimeHour=startHour+"-"+endHour;
 	    		$('.right_time').html("使用时间:"+periodTimeWeek+" "+periodTimeHour);
 	    	
        }
        
    </script>


	<script type="text/javascript">
       var access_token=$.cookie('access_token');
   	   var cid=$.cookie('cid');
   	   var uid=$.cookie('uid');
   	   var comeinType="";
   	   var couponBatchName="";
   	   var copyId="";
	   var name="";
	   var type="";
	   var faceValue="";
	   var validityPeriodType="0";
	   var limitPrice="";
	   var useTimeType=0;
	   var periodTimeWeek="";
	   var periodTimeHour="";
	   var periodTimeHourFlag=false;
   	   var limitPriceFlag=false;
   	   var definedValueFlag=false;
   	   var start_time="";
   	   var end_time="";
   	   var afterDay="";
   	   var sendNum=0;
       var store_ids=new Array();
       var store_names=new Array();
       var useRule=0;
       //标记是否新建优惠券
       var newCouponModel=true;
       //短信通知标记
       var smsInformFlag=1;
       var expireRemindFlag=1;
       var couponName="";
	   var couponId="";
	   var tempCouponId="";
	   var choseInsertActivityUrl=true;
	   var storeIds="";
	   
	   var sms_content="";
	   var remind_content="";
	   var activity_id="";
	   var activity_url="";
	   
	   var noActivity=false;
	   var batchId="";
	   
	   var couponSaveFlag=false;
	   var submitAuditFlag=false;
	   var couponIdsMap=new Map();
	   var couponIds=new Array();
	   
	   var thirdPartyCouponIdsMap=new Map();
	   var thirdPartyCouponIds=new Array();
	   
	   var couponModelType=0;
	   var tempCouponModelType=0;
	   
	   var customerNum=0;
	   var couponNameMap=new Map();
	    var thirdCouponNameMap=new Map();
	   var expireDay=0;
	   var useDesc="";
   	   $(function(){
   		    $('.s_textarea').css("height","");
   		    init();
	   		var myDate = new Date();
	    	//获取当前年
	    	var year=myDate.getFullYear();
	    	//获取当前月
	    	var month=myDate.getMonth()+1;
	    	var lastMoth=myDate.getMonth()+2;
	    	//获取当前日
	    	var day=myDate.getDate(); 
	    	if(day<10)
	        	day="0"+day;
	    	if(month<10)
	    		month="0"+month;
	    	$("#start_time").val(year+"-"+month+"-"+day);
	        $('#start_time').datepicker({  
	            todayBtn : "linked",  
	            autoclose : true,  
	            todayHighlight : true, 
	            startDate : new Date()  
	        }).on('changeDate',function(e){  
	        });
	        if(lastMoth>12){
	        	year=year+1;
	        	lastMoth=lastMoth-12;
	        }
	        if(lastMoth<10)
	        	lastMoth="0"+lastMoth;
				$("#end_time").val(year+"-"+lastMoth+"-"+day);
				$('#end_time').datepicker({
					todayBtn : "linked",
					autoclose : true,
					todayHighlight : true,
					startDate : new Date()
	        	}).on('changeDate',function(e){
	        });
	        reloadRight();
   	   })
   	   
   	   
   	   
   	   function init(){
   		    batchId=getQueryString("id");
   		    comeinType=getQueryString("type");
   		    copyId=getQueryString("copyId");
   		    $('.limit_condition').hide();
   		    if(comeinType=="create"){
   		    	getDetail(batchId);
   		    }else if(comeinType=="edit"){
   		    	getDetail(batchId);
   		    }else if(comeinType=="copy"){
   		    	getDetail(copyId);
   		    }
   		    $('.choseWeek').attr("disabled","disabled");
	   		getAutographList();
	   		var testBsSuggest = $("#testNoBtn").bsSuggest({
	            url: "<%=path%>/activity/ajaxSmsActivity",
	            showBtn: false,
	            delayUntilKeyup: true,
	            effectiveFields: ["name"],
	            idField: "id",
	            keyField: "name"
	        }).on("onDataRequestSuccess", function (e, result) {
	        }).on("onSetSelectValue", function (e, keyWrod) {
	        	activity_id=keyWrod.id;
	        	noActivity=false;
	        	var flag=isHaveStr(showText);
	        	if(!flag){
	        		$('#smsContent').val($('#smsContent').val()+showText);
	        	}
	        	reloadCountWordNum();
	        }).on("onUnsetSelectValue", function (e) {
	        	noActivity=true;
	        });
	   		
		}

		//获取优惠券详情信息
	   	function getDetail(batchId){
	   		var url="<%=path%>/socialCouponBatch/ajaxCouponBatchDetail";
          	$.post(url, {
  				"id":batchId
  			}, function(data) {
  				if (data.status == 200) {
  					initHtml(data.data);
  				}else {
  				    var url="<%=path%>/view/coupon/couponBatch";
                    getDataErrorDialog("获取优惠券批次数据失败",data.message,url);
  				}
  			});
	    	
	    }

       function getDataErrorDialog(title,content,url){
           swal(
               title,
               content,
               'error'
           ).then(function () {
               window.location.href=url;
           })
       }


	   	
	   	function initHtml(data){
	   		customerNum=data.customerNum;
	   		var couponNum = data.couponNum;
	   		if(comeinType=="create"){
	    		return ;
	    	}
			couponBatchName=data.name;
	   	    smsInformFlag=data.smsInformFlag;
	   	    autograph_name=data.autograph;
	      	sms_content=data.smsContent;
	    	remind_content=data.remindContent;
	    	expireRemindFlag=data.expireRemindFlag;
	    	activity_id=data.activityId;
	    	couponId=data.couponIds;
	    	expireDay=data.expireDay;
	    	couponModelType=data.couponModelType;
	    	tempCouponModelType=couponModelType;
	    	$('#couponBatchName').val(couponBatchName);
	    	

	    	if(smsInformFlag==1){
	    		$('.smsSetting').show();
                $('#smsInformNo').removeAttr("checked");
                $('#smsInformNo').parent().removeClass("checked");
                $('#smsInform').attr("checked","checked");
                $('#smsInform').parent().addClass("checked");
	    	}else{
		    	expireRemindFlag=0;
		    	$('.smsSetting').hide();
                $('#smsInform').removeAttr("checked");
                $('#smsInform').parent().removeClass("checked");
                $('#smsInformNo').attr("checked","checked");
                $('#smsInformNo').parent().addClass("checked");
	    	}

	    	if(couponNum>0){
                //选择优惠券
                $('#newCouponRadio').removeAttr("checked");
                $('#newCouponRadio').parent().removeClass("checked");
                $('#newCouponRadioNo').attr("checked","checked");
                $('#newCouponRadioNo').parent().addClass("checked");

                $('.newCoupon').hide();
                $('#choseCouponYet').show();
                newCouponModel=false;
                couponSaveFlag=true;
			}else{
                $('#newCouponRadioNo').removeAttr("checked");
                $('#newCouponRadioNo').parent().removeClass("checked");
                $('#newCouponRadio').attr("checked","checked");
                $('#newCouponRadio').parent().addClass("checked");
                $('.newCoupon').show();
                $('#choseCouponYet').hide();
                newCouponModel=true;
                couponSaveFlag=false;
			}

	    	
	    	$('#smsContent').val(sms_content);
	    	reloadCountWordNum();
	    	//到期提醒
	    	if(expireRemindFlag==0){
	    		$('#expireRemindRadio').removeAttr("checked");
	    		$('#expireRemindRadio').parent().removeClass("checked");
	    		$('#expireRemindRadioNo').attr("checked","checked");
	    		$('#expireRemindRadioNo').parent().addClass("checked");
	    		$('.expireRemind').hide();
	    		$('#expirePrompt').hide();
	    	}else if(expireRemindFlag==1){
	    		$('.expireRemind').show();
	    		$('#expireRemindRadioNo').removeAttr("checked");
	    		$('#expireRemindRadioNo').parent().removeClass("checked");
	    		$('#expireRemindRadio').attr("checked","checked");
	    		$('#expireRemindRadio').parent().addClass("checked");
	    		$('#expireDay').val(expireDay);
	    		$('#ccomment').val(remind_content);
	    		reloadCountWordNumExpire();
	    	}
	    	//插入链接
	    	if(activity_id != null&&activity_id!=0){
	    		$('#insertCouponUrl').removeAttr("checked");
	    		$('#insertCouponUrl').parent().removeClass("checked");
	    		$('#insertShortUrl').attr("checked","checked");
	    		$('#insertShortUrl').parent().addClass("checked");
    			$.post("<%=path%>/activity/ajaxActivityDetail",{id:activity_id},function(data){
    				if(data.status == "200"){
    					var activityObj = data.data;
    	            	var activityName=activityObj.name;
    	            	noActivity=false;
	    				$("#testNoBtn").val(activityName);
    				}
    			});
    		}else{
    			$('#insertShortUrl').removeAttr("checked");
	    		$('#insertShortUrl').parent().removeClass("checked");
	    		
	    		$('#insertCouponUrl').attr("checked","checked");
	    		$('#insertCouponUrl').parent().addClass("checked");
    		}
	    	if(StringEmpty(couponId)){
	    		$('#choseCouponInput').val("已选择");
	    		if(couponModelType == 1){
	    			thirdPartyCouponIds=couponId.split(",");
	    		}else{
	    			couponIds=couponId.split(",");
	    		}
	    	}
	    	$('.right_time').show();
	    	$('.limit_condition').show();
	    	$('.right_hour').show();
	    	$("#right_coupon").css("background-image", "url('<%=path%>/images/marketing/yellow_demo.png')");

	   	}
   	   
   	   
   	   //优惠券派发:保存;提交审核
   	    function save(){
   	      couponBatchName=$("#couponBatchName").val();
   	      if(!StringEmpty(couponBatchName)){
	    	    promptDialog("请输入项目名称");
   		        return ;
  	      }
  	      
   	      //新创建-默认选择短信通知
   	      if(smsInformFlag==1){
	   	      sms_content=$('#smsContent').val();
	   	      if(!StringEmpty(sms_content)){
	   	    		promptDialog("请输入短信内容");
	   	    		return ;
	   	      }
	   	      //选择插入活动链接
	   	      if(choseInsertActivityUrl){
	   	    	if(!StringEmpty(activity_id) && activity_id != 0){
	   	    		promptDialog("保存失败","请选择要插入的活动!");
	        		return "";
	   	    	}
	   	    	if(noActivity){
	   	    		promptDialog("保存失败","您选择的活动不存在，请重新选择!");
	        		return "";
	        	}
	   	      }
	   	      //选择了到期提醒
	   	      if(expireRemindFlag==1){
	   	    	remind_content=$('#ccomment').val();
	   	    	expireDay=$('#expireDay').val();
	   	    	if(!StringEmpty(expireDay)||expireDay==0){
	   	    		promptDialog("请输入短信到期提醒天数");
	   	    		return ;
	   	    	}
	   	    	if(!StringEmpty(remind_content)){
	   	    		promptDialog("请输入到期提醒短信内容");
	   	    		return ;
	   	    	}
	   	      }
   	      }
   	      //选择新建优惠券
   	      if(newCouponModel){
   	    	   saveCouponDefinedTemplate();
   	      }else{
   	    	if(!StringEmpty(couponId)){
   	    		promptDialog("请选择优惠券");
   	    		return ;
   	    	} else{
                updateCouponBatch();
   	    	}
   	      }
   	    }

   	    //保存优惠券配置信息
   	    function saveCouponDefinedTemplate(){
   	    	  var txts=$("#useDesc").val();
              useDesc = '<li>' +txts.replace(/\n/g,'</li><li>') + '</li>';
	   	      name=$("#name").val();
	      	  type= $("input[name='coupon_type']:checked").val();
	   		  faceValue=$("input[name='faceValue']:checked").val();
	   		  useRule=$("input[name='useRule']:checked").val();
	   		  if(faceValue==-1){
	   			 faceValue=$('#defined_value').val();
	   		  }
	   		  if(limitPriceFlag){
	   			limitPrice=$('#limit_price').val();
	   			limitPrice=Number(limitPrice)*100;
	   			limitPrice=parseInt(limitPrice);
	   		  }



	  		  //判断是相对日期还是固定日期
	  		  if(validityPeriodType==0){
	  			  start_time=$('#start_time').val();
	     		  end_time=$('#end_time').val();
	  		  }else if(validityPeriodType==1){
	  			  afterDay=$("#afterDay").val();
	  		  }
	  		  
		  	 /*  periodTimeWeek="";
		      $(".choseWeekLable .checked").children()
				   .each(
						function(i, d) {
							if(StringEmpty(this.id)){
								periodTimeWeek = periodTimeWeek + "," +this.value; 
							}
			  }); */
		      
		     // periodTimeWeek=periodTimeWeek.replace(",","");
	  		  
	  		  if(!StringEmpty(name)){
	  			promptDialog("请输入优惠券名称");
	  			return ;
	  		  }
	  		  //判断是物品全还是优惠券
	  		  if(type==0){
	  			if(!StringEmpty(faceValue)||faceValue==-1){
	  	  			promptDialog("请设置金额");
	  	  			return ;
	  	  		}
	  			faceValue=Number(faceValue)*100;
	  			faceValue=parseInt(faceValue);
	  		  }else{
	  			faceValue=0;
	  		  }
	  		  storeIds=store_ids.join(",");
	  		  if(couponSaveFlag){
	    		   updateDefinedTemplate();
	    	  }else{
                  createDefinedTemplate();
	    	  }
   	    }

   	    //派发优惠券-新创建-保存前先添加优惠券模板
        function createDefinedTemplate(){
        	var url="<%=path%>/couponDefinedTemplate/ajaxCreateDefinedTemplate";
          	$.post(url, {
  				"name":name,
                "type":type,
                "faceValue":faceValue,
                "validityPeriodType":validityPeriodType,
                "limitPrice":limitPrice,
                "useTimeType":useTimeType,
                "periodTimeWeek":periodTimeWeek,
                "periodTimeHour":periodTimeHour,
                "startTimeStr":start_time,
                "endTimeStr":end_time,
                "afterDay":afterDay,
                "storeIds":storeIds,
                "useRule":useRule,
                "useDescribe":useDesc

  			}, function(data) {
  				if (data.status==200) {
  					couponSaveFlag=true;
  					//返回新创建的优惠券模板id
  					couponId=data.data;
                    updateCouponBatch();
  				}else {
  					errorDialog("创建优惠券模板失败",data.message);
  				}
  			});
        }

       //派发优惠券-编辑优惠券批次保存前，先更新优惠券模板信息
        function updateDefinedTemplate(){
        	var url="<%=path%>/couponDefinedTemplate/ajaxUpdateDefinedTemplate";
          	$.post(url, {
  				"name":name,
  				"type":type,
  				"faceValue":faceValue,
  				"validityPeriodType":validityPeriodType,
  				"limitPrice":limitPrice,
  				"useTimeType":useTimeType,
  				"periodTimeWeek":periodTimeWeek,
  				"periodTimeHour":periodTimeHour,
  				"startTimeStr":start_time,
  				"endTimeStr":end_time,
  				"afterDay":afterDay,
  				"storeIds":storeIds,
  				"useRule":useRule,
  				"useDesc":useDesc,
  				"id":couponId,
  			}, function(data) {
  				if (data.status == 200) {
                    updateCouponBatch();
  				}else {
  					errorDialog("创建失败",data.message);
  				}
  			});
        }

        //对优惠券批次进行更新
        function updateCouponBatch(){
           	var url="<%=path%>/socialCouponBatch/ajaxUpdateCouponBatch";
             	$.post(url, {
     				"id":batchId,
     				"name":couponBatchName,
     				"couponIds":couponId,
     				"smsInformFlag":smsInformFlag,
     				"autograph":autograph_name,
     				"smsContent":sms_content,
     				"remindContent":remind_content,
     				"expireRemindFlag":expireRemindFlag,
     				"smsEquivalenNum":smsPriceNum,
     				"smsRemindEquivalenNum":sms_remind_equivalen_num,
     				"activityId":activity_id,
     				"activityUrl":activity_url,
     				"expireDay":expireDay,
     				"couponModelType":couponModelType
     			}, function(data) {
     				if (data.status == 200) {
     					if(submitAuditFlag){
     						submitAudit();
     					}else{
     						OKDialog("保存成功");
     					}
     				} else {
     					errorDialog("保存失败",data.message);
     				}
     			});
           }
        
        
        //提交审核
        function submitAudit(){
        	var url="<%=path%>/socialCouponBatch/ajaxSubmitAudit";
         	$.post(url, {
 				"id":batchId
 			}, function(data) {
 				if (data.status == 200) {
 					OKDialog("提交审核成功");
 				} else {
 					errorDialog("提交审核失败",data.message);
 				}
 			});
        }
        
        
      //获取标签列表
        function getAutographList(){
        	var url="<%=path%>/smsAutograph/ajaxAutographList";
    		$.post( url, function(data) {
    			if (data.status == 200) {
    				setAutographHtml(data.data);
    			}else if(data.message=="20028"){
	        		loginDialog();
	        	}else{
	        		swal(
	        				"获取短信签名失败",
	        				"您还未设置短信签名，请联系您的售后人员创建短信签名，然后再来编辑短信批次内容！",
	            		    'error'
	            		  ).then(function () {
	            			  window.location.href='<%=path%>/view/sms/smsBatch';
	            		})
	        	}
    		});
        }
        //设置签名
        function setAutographHtml(data){
        	var html='';
        	for(var i in data){
        		html+='<option>'+data[i].name+'</option>'
        	}
        	$('#autograph').html(html);
        	reloadCountWordNumExpire();	
        	reloadCountWordNum();
        }
        
        
        function colseModal(){
        	$('#store_modal').modal('hide');
        }
        
        function determineStore(){
        	$('#store_modal').modal('hide');
        	if(store_ids!=null&&StringEmpty(store_ids)){
        		$("#choseStoreIds").val("已选择");
        	}else{
        		$("#choseStoreIds").val("选择优惠券");
        	}
        	
        	
        } 
        
        function determineCoupon(){
        	couponModelType=tempCouponModelType;
        	if(couponModelType == 1){
        		couponId=thirdPartyCouponIds.join(",");
        	}else{
        		couponId=couponIds.join(",");
        	}
        	
        	
        	console.log("couponId--->"+couponId);
        	if(StringEmpty(couponId)){
        		$('#choseCouponInput').val("已选择");
        	}else{
        		$('#choseCouponInput').val("");
        	}
        	$('#coupon_modal').modal('hide');
        }
      
        function colseCouponModal(){
        	$('#coupon_modal').modal('hide');
        }
        
        
        function OKDialog(title,content){
        	swal(
        		    title,
        		    content,
        		    'success'
        		  ).then(function () {
        			  window.location.href='<%=path%>/view/coupon/couponBatch';
        			})
        }
        function num(obj){
        	obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
        	obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
        	obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
        	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        	obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
        	reloadRight();
        }
        
        function handlePeriodTimeWeek(periodTimeWeek){
        	var temp=periodTimeWeek.split(",");
        	if(temp.length==7){
        		return "周一至周日";
        	}else if(temp.length==5){
            	var workDayFlag=true;
        		for(var i in temp){
        			if(temp[i]=="周日"||temp[i]=="周六"){
        				workDayFlag=false;
        				break;
        			}
        		}
        		if(workDayFlag){
        			return "周一至周五";
        		}else{
        			return periodTimeWeek;
        		}
        	}else{
        		return periodTimeWeek;
        	}
        }
        function CompareDate(d1,d2)
        {
          return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/"))));
        }
        
        function cancel(){
            if(comeinType=="create" || comeinType=="copy"){
            	deleteOne();
   		    }else{
   		    	window.location.href="<%=path%>/view/coupon/couponBatch";
   		    }
        }
        
        //删除一个
        function deleteOne(){
        	var url="<%=path%>/socialCouponBatch/ajaxDeleteCouponBatch";
        	$.post(url, {
    			"id" : batchId
    		}, function(data) {
    			window.location.href="<%=path%>/view/coupon/couponBatch";
    		});
        }
        
	</script>

    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
</body>
</html>
